package com.test.encryption;

import com.test.encryption.pojo.OrderShip;
import com.test.encryption.util.AesUtil;
import com.test.encryption.util.RsaUtil;
import org.apache.commons.codec.binary.Base64;

/**
 * @author zhangshijie
 * @date 2021/6/10 10:19
 */
public class TesyComplex {
    public static void main(String[] args) {
        //16位
        String key = "MIGfMA0GCSqGSIb3";

        //复杂对象
        OrderShip orderShip = new OrderShip();

        orderShip.setArea("山西");
        orderShip.setId(1);
        try {
            System.out.println("私钥：" + RsaUtil.getPrivateKey());
            System.out.println("公钥：" + RsaUtil.getPublicKey());

            //公钥加密
            byte[] ciphertext = RsaUtil.encryptByPublicKey(orderShip.toString().getBytes(), RsaUtil.getPublicKey());
            //私钥解密
            byte[] plaintext = RsaUtil.decryptByPrivateKey(ciphertext, RsaUtil.getPrivateKey());

            System.out.println("公钥加密前：" + orderShip.toString());
            System.out.println("公钥加密后：" + Base64.encodeBase64String(ciphertext));
            System.out.println("私钥解密后：" + new String(plaintext));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
